﻿using System;
using System.Collections.Generic;
using SMTC.WebCommon.Common;
using System.Xml;
using SMTC.BO.UserPower;
using SMTC.Model.Model;
using System.Threading;
using SMTC.BO.Employee;

public partial class Themes_Left : BasePage
{
    UserPowerServices _service = new UserPowerServices();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string languagepath;
            if (Thread.CurrentThread.CurrentCulture.Name == "en-US")
            {
                languagepath = "~/Themes/Xml/SiteMapEn.xml";
            }
            else
            {
                languagepath = "~/Themes/Xml/SiteMap.xml";
            }
            List<string> functionlist = new List<string>();
            functionlist = _service.Get_UserFunction_List(((SMT_UserInfo)Session["STMCUser"]).UserID);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath(languagepath));
            XmlNodeList folderlist = xmlDoc.GetElementsByTagName("folder");
            for (int i = 0; i < folderlist.Count; i++)
            {
                XmlNodeList nodelist = xmlDoc.GetElementsByTagName("folder")[i].SelectNodes("node");
                foreach (XmlNode no in nodelist)
                {
                    XmlElement xe = (XmlElement)no;
                    if (!functionlist.Contains(xe.GetAttribute("id")))
                    {
                        no.ParentNode.RemoveChild(no);                     
                    }
                }
          
            }
            string savepath="~/UserXml/"+((SMT_UserInfo)Session["STMCUser"]).UserName+".xml";
            xmlDoc.Save(Server.MapPath(savepath));
            treeSource.DataFile = savepath;
            this.tvNavigation.Focus();
        }
    }

}
